/*
							Copyright (C) 2010  Alourien Team
									
						This file is part of the Alourien Engine.

    The Alourien Engine is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The Alourien Engine is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with the Alourien Engine.  If not, see <http://www.gnu.org/licenses/>.
	
 *File Name: MatrixMathimp.cpp
 *Programmer Name:Jose Castellano
 *Date of last update:10/18/2010
 *
 *Purpose:This Program is to create and Manipulate all the matrices 
 * that are needed for all the work that is used involving 
 * the matrices.
 *
 *Basic Info: This file includes the overloaded operator for addition 
 * both dimensions, overloaded operator for multiplication. The headers that will be
 * required in this would be Matrix2D, Matrix3D, and MatrixMath.
 *
 *UPDATES:
 *1)Created the Program and documentation.
 *  Date:10/18/2010 Updater: Jose Castellano
 *
 *2)Added the matrix concatenation for more than just three matrices
 *  Date:10/19/2010 Updater: Jose Castellano
 *
 *
 */

#include "MatrixMath.h"
#include "Matrix2D.h"
#include "Matrix3D.h"

namespace Alourien
{
	MatrixMath::MatrixMath(void)
	{
	}


	MatrixMath::~MatrixMath(void)
	{
	}
	
	//Creates the rotational matrix for a 2D matrix
	//Returns a 2D Matrix
	Matrix2D MatrixMath::MakeRotational(float angleInDeg)
	{
		Matrix2D tempData;
		
		float angle = toRad * angleInDeg;
		
		tempData.MakeIdentity();
		
		tempData.matArray[0][0] = obj.Cos(angle);
		tempData.matArray[0][1] = obj.Sin(angle) * -1;
		tempData.matArray[1][0] = obj.Sin(angle);
		tempData.matArray[1][1] = obj.Cos(angle);
		
		return tempData;
		
	}
	
	//Creates the rotationalXY matrix for a 3D matrix
	//Returns a 3D Matrix
	Matrix3D MatrixMath::MakeRotationalXY(float angleInDeg)
	{
		Matrix3D tempData;
		
		float angle = toRad * angleInDeg;
		
		tempData.MakeIdentity();
		
		tempData.matArray[0][0] = obj.Cos(angle);
		tempData.matArray[0][1] = obj.Sin(angle) * -1;
		tempData.matArray[1][0] = obj.Sin(angle);
		tempData.matArray[1][1] = obj.Cos(angle);
		
		return tempData;
		
	}
	
	//Creates the rotationalXZ matrix for a 3D matrix
	//Returns a 3D Matrix
	Matrix3D MatrixMath::MakeRotationalXZ(float angleInDeg)
	{
		Matrix3D tempData;
		
		float angle = toRad * angleInDeg;
		
		tempData.MakeIdentity();
		
		tempData.matArray[0][0] = obj.Cos(angle);
		tempData.matArray[2][0] = obj.Sin(angle) * -1;
		tempData.matArray[0][2] = obj.Sin(angle);
		tempData.matArray[2][2] = obj.Cos(angle);
		
		return tempData;
		
	}
	
	//Creates the rotationalYZ matrix for a 3D matrix
	//Returns a 3D Matrix
	Matrix3D MatrixMath::MakeRotationalYZ(float angleInDeg)
	{
		Matrix3D tempData;
		
		float angle = toRad * angleInDeg;
		
		tempData.MakeIdentity();
		
		tempData.matArray[1][1] = obj.Cos(angle);
		tempData.matArray[1][2] = obj.Sin(angle) * -1;
		tempData.matArray[2][1] = obj.Sin(angle);
		tempData.matArray[2][2] = obj.Cos(angle);
		
		return tempData;
		
	}
	
	//Creates the scaling matrix for a 2D matrix
	//Returns a 2D Matrix
	Matrix2D MatrixMath::MakeScaling(float xScaling, float yScaling)
	{
		Matrix2D tempData;
		
		tempData.MakeIdentity();
		
		tempData.matArray[0][0] = xScaling;
		tempData.matArray[1][1] = yScaling;
		
		return tempData;
		
	}
	
	//Creates the scaling matrix for a 3D matrix
	//Returns a 3D Matrix
	Matrix3D MatrixMath::MakeScaling(float xScaling, float yScaling, float zScaling)
	{
		Matrix3D tempData;
		
		tempData.MakeIdentity();
		
		tempData.matArray[0][0] = xScaling;
		tempData.matArray[1][1] = yScaling;
		tempData.matArray[2][2] = zScaling;
		
		return tempData;
		
	}
	
	//Creates the translation matrix for a 2D matrix
	//Returns a 2D Matrix
	Matrix2D MatrixMath::MakeTranslation(float x, float y)
	{
		Matrix2D tempData;
		
		tempData.MakeIdentity();
		
		tempData.matArray[0][2] = x;
		tempData.matArray[1][2] = y;
		
		return tempData;
	}
	
	//Creates the translation matrix for a 3D matrix
	//Returns a 3D Matrix
	Matrix3D MatrixMath::MakeTranslation(float x, float y, float z)
	{
		Matrix3D tempData;
		
		tempData.MakeIdentity();
		
		tempData.matArray[0][3] = x;
		tempData.matArray[1][3] = y;
		tempData.matArray[2][3] = z;
		
		return tempData;
	}
	
	//Creates the matrix that concatinates all the transformations for a 2D matrix
	//Returns a 2D Matrix
	Matrix2D MatrixMath::CreateConcatinated(Matrix2D matScale, Matrix2D matRot, \
									Matrix2D matTrans)
	{
		return matTrans * matScale * matRot;
	}
	
	//Creates the matrix that concatinates all the transformations for a 3D matrix
	//Returns a 3D Matrix
	Matrix3D MatrixMath::CreateConcatinated(Matrix3D matScale, Matrix3D matRot, \
									Matrix3D matTrans)
	{
		return matTrans * matScale * matRot;
	}
	
	//Creates the matrix that concatinates all the transformations for a 3D matrix
	//Returns a 3D Matrix
	Matrix3D MatrixMath::CreateConcatinated(Matrix3D matScale, Matrix3D matRot, \
						Matrix3D matRot2,	Matrix3D matTrans)
	{
		Matrix3D temp;
		temp = matRot * matRot2;
		return matTrans * matScale * temp;
	}
	
	//Creates the matrix that concatinates all the transformations for a 3D matrix
	//Returns a 3D Matrix
	Matrix3D MatrixMath::CreateConcatinated(Matrix3D matScale, Matrix3D matRot, \
				Matrix3D matRot2,Matrix3D matRot3,	Matrix3D matTrans)
	{
		Matrix3D temp;
		temp = matRot * matRot2 * matRot3;
		return matTrans * matScale * temp;
	}

}